package kr.co.doriclassic.chapter17;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;

import java.awt.BorderLayout;

import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ImageLabelEx extends JPanel implements ActionListener {
	private JLabel label;
	private JButton button;
	private JLabel panelImage;

	/**
	 * Create the panel.
	 */
	public ImageLabelEx() {

		initialize();
	}
	private void initialize() {
		setLayout(new BorderLayout(0, 0));
		
		label = new JLabel("이미지를 보려면 아래 버튼을 누르시오");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		add(label, BorderLayout.NORTH);
		
		button = new JButton("이미지레이블");
		button.addActionListener(this);
		add(button, BorderLayout.SOUTH);
				
		panelImage = new JLabel();
		panelImage.setHorizontalAlignment(SwingConstants.CENTER);
		add(panelImage, BorderLayout.CENTER);
	}

	public void actionPerformed(ActionEvent e) {
		
		if (e.getSource() == button) {
			ImageIcon icon = new ImageIcon("img.jpg");
			panelImage.setIcon(icon);
		}
	}
	
}
